package com.woniu.humanresource.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.woniu.humanresource.entity.Accets;
import com.woniu.humanresource.entity.AssetsCategory;
import com.woniu.humanresource.entity.ResponseText;
import com.woniu.humanresource.entity.Warehouse;
import com.woniu.humanresource.service.AssetsCategoryService;
import com.woniu.humanresource.service.WarehouseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class WarehouseController {
    @Autowired
    WarehouseService warehouseService;

    //查询所有
    @PostMapping("/warehouse")
    public ResponseText<List<Warehouse>> getAllWarehouse(){

        List<Warehouse> allWarehouse = warehouseService.getAllWarehouse();//调service方法去查询
        ResponseText<List<Warehouse>> responseText=new ResponseText<>(allWarehouse, 200, "OK");//返回一个带有树状的分类
        return responseText;
    }

    //添加根节点
    @PostMapping("/addRootNodeWarehouse/{newWarehouseName}/{newWarehouseNum}/{newWarehouseAddress}/{newWarehouseRemarks}")
    public ResponseText<List<Warehouse>> addRootNodeWarehouse(@PathVariable("newWarehouseName") String newWarehouseName,
                                                                   @PathVariable("newWarehouseNum") String newWarehouseNum,
                                                                   @PathVariable("newWarehouseAddress") String newWarehouseAddress,
                                                                   @PathVariable("newWarehouseRemarks") String newWarehouseRemarks){

        System.out.println("■■■■■■添加■■■■■■"+newWarehouseName+"/"+newWarehouseNum+"/"+newWarehouseAddress+"/"+newWarehouseRemarks);

        warehouseService.addRootNodeWarehouse(newWarehouseName,newWarehouseNum,newWarehouseAddress,newWarehouseRemarks);//调service方法去插入
        ResponseText<List<Warehouse>> responseText=new ResponseText<>(null, 200, "OK");//返回一个空信息的状态响应
        return responseText;
    }

    //添加子节点分类
    @PostMapping("/addWarehouse/{newWarehouseName}/{newWarehouseNum}/{newWarehouseAddress}/{newWarehouseRemarks}")
    public ResponseText<List<Warehouse>> addWarehouse(@PathVariable("newWarehouseName") String newWarehouseName,
                                                                @PathVariable("newWarehouseNum") String newWarehouseNum,
                                                                @PathVariable("newWarehouseAddress") String newWarehouseAddress,
                                                                @PathVariable("newWarehouseRemarks") String newWarehouseRemarks,
                                                                @RequestBody Warehouse warehouse){

        System.out.println("■■■■■■添加■■■■■■"+newWarehouseName+"/"+newWarehouseNum+"/"+newWarehouseAddress+"/"+newWarehouseRemarks+"/"+warehouse);

        warehouseService.addWarehouse(newWarehouseName,newWarehouseNum,newWarehouseAddress,newWarehouseRemarks,warehouse);//调service方法去插入
        ResponseText<List<Warehouse>> responseText=new ResponseText<>(null, 200, "OK");//返回一个空信息的状态响应
        return responseText;
    }

    //删除
    @DeleteMapping("/removeWarehouse")
    public ResponseText<Page<Warehouse>> removeWarehousesByIds(@RequestBody List<Warehouse> warehouses){

        System.out.println("■■■■■■删除■■■■■■"+warehouses);

        warehouseService.removeWarehousesByIds(warehouses);
        ResponseText<Page<Warehouse>> responseText=new ResponseText<>(null, 200, "OK");
        return responseText;
    }

    //编辑
    @PutMapping("/editWarehouse/{newWarehouseName}/{newWarehouseNum}/{newWarehouseAddress}/{newWarehouseRemarks}")
    public ResponseText<List<Warehouse>> editWarehouse(@PathVariable("newWarehouseName") String newWarehouseName,
                                                                 @PathVariable("newWarehouseNum") String newWarehouseNum,
                                                                 @PathVariable("newWarehouseAddress") String newWarehouseAddress,
                                                                 @PathVariable("newWarehouseRemarks") String newWarehouseRemarks,
                                                                 @RequestBody Warehouse warehouse){

        System.out.println("■■■■■■编辑■■■■■■"+newWarehouseName+"/"+newWarehouseNum+"/"+newWarehouseAddress+"/"+newWarehouseRemarks+"/"+warehouse);

        warehouseService.editWarehouse(newWarehouseName,newWarehouseNum,newWarehouseAddress,newWarehouseRemarks,warehouse);//调service方法去插入
        ResponseText<List<Warehouse>> responseText=new ResponseText<>(null, 200, "OK");//返回一个空信息的状态响应
        return responseText;
    }
}
